﻿using System;
using System.Collections.Generic;
using System.Linq;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using YArchitech.Controls;
using YArchitech.Revit;
using Transfer.CrossFloor;

namespace YArchitech.HVAC
{
	public class DifferentialPressureOperation
	{
		public DifferentialPressureOperation(UIDocument UiDoc, FrmDifferentialPressure Frm, ExternalCommandData M_Revit)
		{
			this.uiDoc = UiDoc;
			this.doc = UiDoc.Document;
			this.sel = UiDoc.Selection;
			this.frm = Frm;
			this.m_Revit = M_Revit;
		}

		public void layfs(Transaction tran)
		{
			FamilySymbol familySymbol = null;
			try
			{
				familySymbol = new PressDuctTerminalOperation(this.uiDoc, null).GetFamilySymbolyByName("EquipmentSanitary", "压差传感器.rfa", "标准", BuiltInCategory.OST_MechanicalEquipment);
				tran.Commit();
			}
			catch (Exception)
			{
                if (tran != null && (int)tran.GetStatus() == 3)
				{
					tran.RollBack();
				}
			}
			HYEquipmentCommon hyequipmentCommon = new HYEquipmentCommon();
			ICollection<ElementId> allFamilyInstance = hyequipmentCommon.GetAllFamilyInstance(this.doc, BuiltInCategory.OST_MechanicalEquipment);
			Transaction transaction = new Transaction(this.doc, "布置");
			ICollection<ElementId> collection = null;
			ICollection<ElementId> collection2 = null;
			try
			{
				if (!this.frm.cbByWall.Checked)
				{
					try
					{
						this.uiDoc.PromptForFamilyInstancePlacement(familySymbol);
					}
					catch (Exception)
					{
					}
					transaction.Start();
					collection = hyequipmentCommon.GetAllFamilyInstance(this.doc, BuiltInCategory.OST_MechanicalEquipment);
					collection2 = collection.Except(allFamilyInstance).ToList<ElementId>();
					this.setParamInDifferentialPressure(collection2);
				}
				else
				{
					transaction.Start();
					try
					{
						for (;;)
						{
							this.layByWall(familySymbol);
						}
					}
					catch (Autodesk.Revit.Exceptions.OperationCanceledException)
					{
					}
					catch (Exception ex)
					{
						throw ex;
					}
					collection = hyequipmentCommon.GetAllFamilyInstance(this.doc, BuiltInCategory.OST_MechanicalEquipment);
					collection2 = collection.Except(allFamilyInstance).ToList<ElementId>();
				}
			}
			catch (Exception)
			{
                if ((int)transaction.GetStatus() == 1)
				{
					transaction.RollBack();
				}
			}
            if ((int)transaction.GetStatus() == 1)
			{
				transaction.Commit();
			}
			if (this.frm.cbLevel.Checked && collection2 != null)
			{
				this.copyDifferentialPressureToLevel(collection2);
				ICollection<ElementId> collectionId;
				if (collection != null)
				{
					collectionId = hyequipmentCommon.GetAllFamilyInstance(this.doc, BuiltInCategory.OST_MechanicalEquipment).Except(collection).ToList<ElementId>();
				}
				else
				{
					collectionId = hyequipmentCommon.GetAllFamilyInstance(this.doc, BuiltInCategory.OST_MechanicalEquipment);
				}
				if (this.frm.cbByWall.Checked)
				{
					this.checkDeleteItem(collectionId);
				}
			}
		}

		private void checkDeleteItem(ICollection<ElementId> collectionId)
		{
			bool flag = false;
			string text = string.Empty;
			foreach (ElementId elementId in collectionId)
			{
				Element element = this.doc.GetElement(elementId);
				BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(this.doc.ActiveView);
				BoundingBoxIntersectsFilter boundingBoxIntersectsFilter = new BoundingBoxIntersectsFilter(new Outline(boundingBoxXYZ.Min, boundingBoxXYZ.Max));
				List<Element> list = new FilteredElementCollector(this.doc).OfClass(typeof(Wall)).WherePasses(boundingBoxIntersectsFilter).ToElements().ToList<Element>();
				foreach (LinkedDocument linkedDocument in this.doc.GetLinkedDocuments())
				{
					List<Element> source = new FilteredElementCollector(linkedDocument.Document).OfClass(typeof(Wall)).WherePasses(boundingBoxIntersectsFilter).ToElements().ToList<Element>();
					list.AddRange(source.ToList<Element>());
				}
				if (list == null || list.Count<Element>() == 0)
				{
					text = text + "\n" + this.doc.GetElement(element.LevelId).Name;
					flag = true;
					Transaction transaction = new Transaction(this.doc, "删除");
					transaction.Start();
					this.doc.Delete(elementId);
					transaction.Commit();
				}
			}
			if (flag)
			{
				YJKMessageBox.Information("以下楼层的墙体布局与其他标准层不一致，请单独布置压差传感器:" + text);
			}
		}

		private void layByWall(FamilySymbol fs)
		{
			XYZ xyz = new XYZ();
			XYZ xyz2 = new XYZ();
			XYZ xyz3 = new XYZ();
			double num = 0.0;
			bool flag = true;
			bool flag2 = false;
			List<XYZ> list = new List<XYZ>();
			Transform transform = null;
			XYZ xyz4 = null;
			Line line = this.SelectWall(ref xyz, ref xyz2, ref num, ref flag, ref flag2, ref transform, ref xyz3, ref xyz4) as Line;
			if (line == null)
			{
				YJKMessageBox.Information("没有选到墙边线，请将鼠标放到墙边线上，亮显后再确定！");
			}
			if (line != null)
			{
				YJKLine hyline = new YJKLine(line);
				double num2 = 100000.0;
				if (hyline.StartPoint.X != hyline.EndPoint.X)
				{
					num2 = hyline.lookForK(hyline.StartPoint, hyline.EndPoint);
				}
				XYZ calPoint;
				if (flag)
				{
					calPoint = new XYZ(xyz2.X, xyz2.Y + 0.1, xyz2.Z);
					if (num2 == 0.0)
					{
						num2 = -1E-06;
					}
				}
				else
				{
					calPoint = new XYZ(xyz2.X, xyz2.Y - 0.1, xyz2.Z);
					if (num2 == 0.0)
					{
						num2 = 1E-06;
					}
				}
				if (num2 > 1000.0 || num2 < -1000.0)
				{
					if (flag)
					{
						calPoint = new XYZ(xyz2.X - 1.0, xyz2.Y, xyz2.Z);
					}
					else
					{
						calPoint = new XYZ(xyz2.X + 1.0, xyz2.Y, xyz2.Z);
					}
				}
				int num3 = this.GetPointPosition(xyz, xyz2, calPoint);
				int num6;
				if (num2 != 0.0)
				{
					double num4 = xyz.Y + 1.0 / num2 * xyz.X;
					double num5 = -1.0 / num2 * (xyz.X + 1.0) + num4;
					num6 = this.GetPointPosition(xyz, new XYZ(xyz.X + 1.0, num5, xyz.Z), calPoint);
				}
				else
				{
					num6 = this.GetPointPosition(xyz, new XYZ(xyz.X + 1.0, xyz.Y, xyz.Z), calPoint);
				}
				if (num2 > 0.0)
				{
					num3 = -num3;
					num6 = -num6;
				}
				if (num2 != 0.0)
				{
					XYZ item = this.GetPos(this.GetPos(xyz, num2, xyz3.DistanceTo(xyz), -num6), -1.0 / num2, 0.0, num3);
					list.Add(item);
				}
				else
				{
					XYZ item = new XYZ(xyz.X + 0.0, xyz.Y + (double)(-(double)num3) * xyz3.DistanceTo(xyz), xyz.Z);
					list.Add(item);
				}
				foreach (XYZ xyz5 in list)
				{
					XYZ xyz6 = xyz5;
					if (transform != null)
					{
						xyz6 = xyz5 + transform.Origin;
					}
					UnifiedModified.ActivateFamilySymbol(fs);
					FamilyInstance familyInstance = this.doc.Create.NewFamilyInstance(new XYZ(xyz6.X, xyz6.Y, Convert.ToDouble(this.frm.hyTextBox1.Text) * 1000.0 / 304.8), fs, this.uiDoc.ActiveView.GenLevel, 0);
					this.doc.Regenerate();
					double num7 = Math.Atan(num2);
					if (xyz4 != null && xyz4.Y > xyz3.Y)
					{
						num3 = -num3;
					}
					if (num3 == 1)
					{
						if (num2 > 0.0)
						{
							num7 = Math.PI - num7;
						}
						else
						{
							Parameter parameter = familyInstance.GetParameter("平面图例（上）");
							if (parameter != null && !parameter.IsReadOnly)
							{
								parameter.Set(0);
							}
							num7 = -num7;
						}
					}
					else if (num2 > 0.0)
					{
						Parameter parameter2 = familyInstance.GetParameter("平面图例（上）");
						if (parameter2 != null && !parameter2.IsReadOnly)
						{
							parameter2.Set(0);
						}
						num7 = -num7;
					}
					else
					{
						num7 = Math.PI - num7;
					}
					ElementTransformUtils.RotateElement(this.doc, familyInstance.Id, Line.CreateBound(xyz6, new XYZ(xyz6.X, xyz6.Y, xyz6.Z + 1.0)), Math.PI - num7);
				}
			}
		}

		private XYZ GetPos(XYZ oriPos, double k, double fLen, int d1)
		{
			if (k < 10000.0)
			{
				double num = (double)d1 * Math.Sqrt(fLen * fLen / (k * k + 1.0)) + oriPos.X;
				double num2 = k * (num - oriPos.X) + oriPos.Y;
				return new XYZ(num, num2, oriPos.Z);
			}
			return new XYZ(oriPos.X, oriPos.Y + (double)d1 * fLen, oriPos.Z);
		}

		private int GetPointPosition(XYZ originPoint, XYZ linePoint, XYZ calPoint)
		{
			if (Math.Abs(linePoint.X - originPoint.X) < 0.001)
			{
				if (linePoint.X < calPoint.X)
				{
					return 1;
				}
				return -1;
			}
			else
			{
				double num = (linePoint.Y - originPoint.Y) / (linePoint.X - originPoint.X);
				double num2 = linePoint.Y - num * linePoint.X;
				if (num * calPoint.X + num2 < calPoint.Y)
				{
					return 1;
				}
				return -1;
			}
		}

		private Curve SelectWall(ref XYZ startPoint, ref XYZ endPoint, ref double z, ref bool isUpLine, ref bool isArcWall, ref Transform trans, ref XYZ selectedPoint, ref XYZ center)
		{
			Reference reference = null;
			Line line = null;
			try
			{
                SelectedElement selectedElement = this.uiDoc.PickElementsByFace<Element>("请选择要布置的参考墙面", ref reference, ref trans, 0.05);
				if (selectedElement == null)
				{
					return line;
				}
				Element element = selectedElement.Element;
				Wall wall = element as Wall;
				z = this.uiDoc.ActiveView.GenLevel.Elevation;
				Options options = new Options();
				options.ComputeReferences = true;
				Face face = null;
				try
				{
					GeometryObject geometryObjectFromReference = element.GetGeometryObjectFromReference(reference);
					if (geometryObjectFromReference is CylindricalFace)
					{
						face = (geometryObjectFromReference as CylindricalFace);
						center = ((CylindricalFace)face).Origin;
						isArcWall = true;
					}
					else
					{
						face = ((geometryObjectFromReference as Face) as PlanarFace);
					}
				}
				catch (Exception)
				{
					face = this.GetNearestFaceFromElement(element, reference.GlobalPoint, trans);
					if (face is CylindricalFace)
					{
						center = ((CylindricalFace)face).Origin;
						isArcWall = true;
					}
				}
				double maxValue = double.MaxValue;
				double num = double.MinValue;
				double num2 = 0.0;
				line = this.getLine(face, reference, trans, ref maxValue, ref num, ref num2, selectedElement.SelectedPoint);
				if (isArcWall)
				{
					IEnumerator<GeometryObject> enumerator = wall.get_Geometry(options).GetEnumerator();
					{
						while (enumerator.MoveNext())
						{
							GeometryObject geometryObject = enumerator.Current;
							if (geometryObject is Solid)
							{
								Solid solid = geometryObject as Solid;
								if (solid != null && solid.Faces.Size > 0)
								{
									foreach (object obj in solid.Faces)
									{
										Face face2 = (Face)obj;
										if (face2 is CylindricalFace && face2 != face)
										{
											if (((CylindricalFace)face2).Area > face.Area)
											{
												isUpLine = false;
												break;
											}
											isUpLine = true;
											break;
										}
									}
								}
							}
						}
						goto IL_52D;
					}
				}
				foreach (GeometryObject geometryObject2 in wall.get_Geometry(options))
				{
					if (geometryObject2 is Solid)
					{
						Solid solid2 = geometryObject2 as Solid;
						if (solid2 != null && solid2.Edges.Size > 0)
						{
							foreach (object obj2 in solid2.Edges)
							{
								Edge edge = (Edge)obj2;
								if (Math.Abs(edge.Tessellate()[0].Z - edge.Tessellate()[1].Z) < 0.01)
								{
									YJKLine hyline = new YJKLine(edge.Tessellate()[0], edge.Tessellate()[1]);
									if (Math.Abs(line.Tessellate()[0].Y - line.Tessellate()[1].Y) < 0.01)
									{
										if (Math.Abs(edge.Tessellate()[0].Y - edge.Tessellate()[1].Y) < 0.01)
										{
											num2 = line.Tessellate()[0].Y;
											if (edge.Tessellate()[0].Y > num)
											{
												num = edge.Tessellate()[0].Y;
											}
										}
									}
									else if (Math.Abs(line.Tessellate()[0].X - line.Tessellate()[1].X) < 0.01)
									{
										if (Math.Abs(edge.Tessellate()[0].X - edge.Tessellate()[1].X) < 0.01)
										{
											num2 = line.Tessellate()[0].X;
											if (edge.Tessellate()[0].X > num)
											{
												num = edge.Tessellate()[0].X;
											}
										}
									}
									else if (edge.Tessellate().Count<XYZ>() == 2 && Math.Abs(1.0 - hyline.lookForK(edge.Tessellate()[0], edge.Tessellate()[1]) / hyline.lookForK(line.Tessellate()[0], line.Tessellate()[1])) < 0.01 && this.GetB(edge.Tessellate()[0], edge.Tessellate()[1]) > num)
									{
										num = this.GetB(edge.Tessellate()[0], edge.Tessellate()[1]);
									}
								}
							}
						}
					}
				}
				if (num2 - num < -0.01)
				{
					isUpLine = false;
				}
				else
				{
					isUpLine = true;
				}
				IL_52D:
				if (line != null)
				{
					YJKLine hyline2 = new YJKLine(line);
					startPoint = hyline2.GetNearlyPoint(reference.GlobalPoint);
					if (trans != null)
					{
						startPoint = hyline2.GetNearlyPoint(reference.GlobalPoint - trans.Origin);
					}
					if (startPoint.DistanceTo(line.Tessellate()[0]) > startPoint.DistanceTo(line.Tessellate()[1]))
					{
						endPoint = line.Tessellate()[0];
					}
					else
					{
						endPoint = line.Tessellate()[1];
					}
					selectedPoint = line.Project(selectedElement.SelectedPoint).XYZPoint;
				}
			}
			catch (Autodesk.Revit.Exceptions.OperationCanceledException ex)
			{
				throw ex;
			}
			catch (Exception)
			{
				return line;
			}
			return line;
		}

		private Line getLine(Face face, Reference reference, Transform trans, ref double minDis, ref double maxb, ref double lineb, XYZ SelectedPoint)
		{
			Line line = null;
			foreach (object obj in face.EdgeLoops)
			{
				foreach (object obj2 in ((EdgeArray)obj))
				{
					Edge edge = (Edge)obj2;
					if (edge.Tessellate().Count == 2)
					{
						if (Math.Abs(edge.Tessellate()[0].Z - edge.Tessellate()[1].Z) < 0.01)
						{
							Line line2 = Line.CreateBound(edge.Tessellate()[0], edge.Tessellate()[1]);
							double num = line2.Distance(reference.GlobalPoint);
							if (trans != null)
							{
								num = line2.Distance(reference.GlobalPoint - trans.Origin);
							}
							if (num < minDis)
							{
								minDis = num;
								lineb = this.GetB(edge.Tessellate()[0], edge.Tessellate()[1]);
								line = line2;
							}
						}
					}
					else
					{
						XYZ xyz = null;
						XYZ xyz2 = null;
						foreach (XYZ item in edge.Tessellate())
						{
							this.setPt(ref xyz, ref xyz2, item, SelectedPoint);
						}
						if (xyz != null && xyz2 != null)
						{
							line = Line.CreateBound(xyz, xyz2);
							double num2 = line.Distance(reference.GlobalPoint);
							if (trans != null)
							{
								num2 = line.Distance(reference.GlobalPoint - trans.Origin);
							}
							if (num2 <= minDis)
							{
								minDis = num2;
								lineb = this.GetB(xyz, xyz2);
							}
						}
					}
				}
			}
			return line;
		}

		private void setPt(ref XYZ firstPt, ref XYZ secondPt, XYZ item, XYZ selectPt)
		{
			if (firstPt == null)
			{
				firstPt = new XYZ(item.X, item.Y, selectPt.Z);
				return;
			}
			if (secondPt == null)
			{
				double num = firstPt.DistanceTo(selectPt);
				if (item.DistanceTo(selectPt) < num)
				{
					secondPt = firstPt;
					firstPt = new XYZ(item.X, item.Y, selectPt.Z);
					return;
				}
				secondPt = new XYZ(item.X, item.Y, selectPt.Z);
				return;
			}
			else
			{
				double num2 = firstPt.DistanceTo(selectPt);
				double num3 = secondPt.DistanceTo(selectPt);
				double num4 = new XYZ(item.X, item.Y, selectPt.Z).DistanceTo(selectPt);
				if (num2 < num4 && num3 > num4)
				{
					secondPt = new XYZ(item.X, item.Y, selectPt.Z);
					return;
				}
				if (num2 > num4 && num3 > num4)
				{
					secondPt = firstPt;
					firstPt = new XYZ(item.X, item.Y, selectPt.Z);
				}
				return;
			}
		}

		private Face GetNearestFaceFromElement(Element e, XYZ globalPoint, Transform trans)
		{
			PlanarFace planarFace = null;
			CylindricalFace result = null;
			try
			{
				foreach (GeometryObject geometryObject in (e as Wall).get_Geometry(new Options
				{
					ComputeReferences = true
				}))
				{
					if (geometryObject is Solid)
					{
						Solid solid = geometryObject as Solid;
						if (solid != null && solid.Edges.Size > 0)
						{
							double num = double.MaxValue;
							foreach (object obj in solid.Faces)
							{
								Face face = (Face)obj;
								if (this.isVerticalFace(face))
								{
									if (face is PlanarFace)
									{
										double num2 = double.MaxValue;
										foreach (object obj2 in face.EdgeLoops)
										{
											foreach (object obj3 in ((EdgeArray)obj2))
											{
												Edge edge = (Edge)obj3;
												if (Math.Abs(edge.Tessellate()[0].Z - edge.Tessellate()[1].Z) < 0.1)
												{
													double num3 = Line.CreateBound(edge.Tessellate()[0], edge.Tessellate()[1]).Distance(globalPoint - trans.Origin);
													if (num3 < num2)
													{
														num2 = num3;
													}
												}
											}
										}
										if (num2 < num)
										{
											num = num2;
											planarFace = (face as PlanarFace);
											result = null;
										}
									}
									else
									{
										foreach (object obj4 in face.EdgeLoops)
										{
											foreach (object obj5 in ((EdgeArray)obj4))
											{
												Edge edge2 = (Edge)obj5;
												XYZ xyz = null;
												XYZ xyz2 = null;
												if (edge2.Tessellate().Count != 2)
												{
													foreach (XYZ item in edge2.Tessellate())
													{
														this.setPt(ref xyz, ref xyz2, item, globalPoint);
													}
													if (xyz != null && xyz2 != null)
													{
														double num4 = Line.CreateBound(xyz, xyz2).Distance(globalPoint);
														if (num4 < num)
														{
															num = num4;
															planarFace = null;
															result = (face as CylindricalFace);
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			catch (Exception)
			{
			}
			if (planarFace == null)
			{
				return result;
			}
			return planarFace;
		}

		private bool isVerticalFace(Face f)
		{
			foreach (object obj in f.EdgeLoops)
			{
				foreach (object obj2 in ((EdgeArray)obj))
				{
					Edge edge = (Edge)obj2;
					if (Math.Abs(edge.Tessellate()[0].Z - edge.Tessellate()[1].Z) > 0.1)
					{
						return true;
					}
				}
			}
			return false;
		}

		private double GetB(XYZ point1, XYZ point2)
		{
			if (point1.X - point2.X == 0.0)
			{
				return double.MaxValue;
			}
			double num = (point1.Y - point2.Y) / (point1.X - point2.X);
			return point1.Y - num * point1.X;
		}

		private void copyDifferentialPressureToLevel(ICollection<ElementId> collectionId2)
		{
			List<ViewPlan> list = new List<ViewPlan>();
			this.SelectFloorViewPlans(this.doc, collectionId2, ref list);
			foreach (Autodesk.Revit.DB.View view in list)
			{
				RevitVersionFuncs.CreateTranslation(new XYZ(0.0, 0.0, view.GenLevel.Elevation - this.doc.ActiveView.GenLevel.Elevation));
				AutoCopyEntitiesManager autoCopyEntitiesManager = new AutoCopyEntitiesManager(this.m_Revit);
				bool copyWindows = false;
				bool copyDoors = false;
				bool copyOpenings = false;
				List<List<ElementId>> list2 = new List<List<ElementId>>();
				list2.Add(collectionId2.ToList<ElementId>());
				autoCopyEntitiesManager.Copy(view, Transform.Identity, list2, copyWindows, copyDoors, copyOpenings);
			}
		}

		public bool SelectFloorViewPlans(Autodesk.Revit.DB.Document doc, ICollection<ElementId> collectionId2, ref List<ViewPlan> selectFloorLevels)
		{
			List<Level> sortLevels = this.GetSortLevels(doc, double.MinValue, double.MaxValue);
			List<ViewPlan> list = new List<ViewPlan>();
			List<double> list2 = new List<double>();
			foreach (Element element in new FilteredElementCollector(doc).OfClass(typeof(ViewPlan)))
			{
				ViewPlan viewPlan = element as Autodesk.Revit.DB.ViewPlan;
                if (viewPlan != null && (int)viewPlan.ViewType == 1 && viewPlan.GenLevel != null)
				{
					list2.Add(viewPlan.GenLevel.Elevation);
					list.Add(viewPlan);
				}
			}
			List<ViewPlan> list3 = new List<ViewPlan>();
			for (int i = 0; i < sortLevels.Count; i++)
			{
				for (int j = 0; j < list2.Count; j++)
				{
					if (this.IsEqual(sortLevels[i].Elevation, list2[j]))
					{
						list3.Add(list[j]);
					}
				}
			}
			List<ViewPlan> list4 = list3.Distinct(new DifferentialPressureOperation.LevelEqualityComparer()).ToList<ViewPlan>();
			list4 = (from l in list4
			where l.GenLevel.Id != doc.ActiveView.GenLevel.Id
			select l).ToList<ViewPlan>();
			(from l in list4
			select l.GenLevel).ToList<Level>();
			if (this.frm.Indexs != null)
			{
				foreach (int index in this.frm.Indexs)
				{
					selectFloorLevels.Add(list4[index]);
				}
			}
			return true;
		}

		private bool IsEqual(double val1, double val2)
		{
			return !this.LessThan(val1, val2) && !this.LessThan(val2, val1);
		}

		private bool LessThan(double val1, double val2)
		{
			return val1 - val2 < -1E-09;
		}

		private List<Level> GetSortLevels(Autodesk.Revit.DB.Document doc, double bottom, double top)
		{
			List<Level> list = new List<Level>();
			foreach (Element element in new FilteredElementCollector(doc).OfClass(typeof(Level)).ToElements())
			{
				Level level = element as Level;
				double elevation = level.Elevation;
				if (elevation >= bottom && elevation <= top)
				{
					list.Add(level);
				}
			}
			list.Sort(new DifferentialPressureOperation.LevelComparer());
			return list;
		}

		private void setParamInDifferentialPressure(ICollection<ElementId> collectionId2)
		{
			foreach (ElementId elementId in collectionId2)
			{
				Element element = this.doc.GetElement(elementId);
				Parameter parameter = element.GetParameter(BuiltInParameter.RBS_OFFSET_PARAM);
				if (parameter == null)
				{
					parameter = element.GetParameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
				}
				if (parameter != null && !parameter.IsReadOnly)
				{
					parameter.Set(Convert.ToDouble(this.frm.hyTextBox1.Text) * 1000.0 / 304.8);
				}
			}
		}

		private Document doc;

		private UIDocument uiDoc;

		private FrmDifferentialPressure frm;

		private Selection sel;

		private ExternalCommandData m_Revit;

		private const double _epsDouble = 1E-09;

		private class LevelComparer : IComparer<Level>
		{
			public int Compare(Level x, Level y)
			{
				return x.Elevation.CompareTo(y.Elevation);
			}
		}

		private class LevelEqualityComparer : IEqualityComparer<ViewPlan>
		{
			public bool Equals(ViewPlan ele1, ViewPlan ele2)
			{
				return ele1.GenLevel.Elevation == ele2.GenLevel.Elevation;
			}

			public int GetHashCode(ViewPlan obj)
			{
				return obj.ToString().GetHashCode();
			}
		}
	}
}
